#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <arpa/inet.h>

#define SERVER_IP "192.168.209.135"  // 服务器的 IP 地址
#define PORT 8080  // 服务器的端口

int main() {
    int sock = 0;
    struct sockaddr_in server_address;
    char *message = "Hello from CentOS 7!";
    char buffer[1024] = {0};
    if ((sock = socket(AF_INET, SOCK_STREAM, 0)) < 0) {
        perror("Socket creation failed");
        exit(EXIT_FAILURE);
    }
    server_address.sin_family = AF_INET;
    server_address.sin_port = htons(PORT);
    if (inet_pton(AF_INET, SERVER_IP, &server_address.sin_addr) <= 0) {
        perror("Invalid address");
        exit(EXIT_FAILURE);
    }
    if (connect(sock, (struct sockaddr *)&server_address, sizeof(server_address)) < 0) {
        perror("Connection failed");
        exit(EXIT_FAILURE);
    }
    send(sock, message, strlen(message), 0);
    printf("Message sent to server: %s\n", message);
    read(sock, buffer, sizeof(buffer));
    printf("Received response: %s\n", buffer);
    close(sock);

    return 0;
}

